package com.atguigu.servicebase.exception;

import com.atguigu.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class MyExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R GlobalExceptionHandler(Exception e){

        e.printStackTrace();//输出异常信息
        return R.error().data("异常信息",e.getMessage());
    }


    @ExceptionHandler(GuliException.class)
    @ResponseBody
    public R GuliExceptionHandler(GuliException e){

        e.printStackTrace();
        log.error(e.getMessage());

        return R.error().data("自定义异常：",e.getMsg());
    }


}
